@extends('layouts.app')
@section('content')
    <div class="content">
        <div class="row custom-invoice">
            <div>
                <form class="form form-inline" method="get" action="{{ route('admin.withdrawal.index') }}"  autocomplete="off">
                    <div class="form-group form-inline">
                        <label for="delivery">订单类型: </label>
                        @php
                            use \App\Modules\Withdrawal\Models\Withdrawal;
                        @endphp
                        <select class="form-control" name="is_success">
                            <option value="" {{ $isSuccess == ""? "selected":"" }}>全部</option>
                            <option
                                value="{{Withdrawal::STATUS_INIT}}" {{ $isSuccess == Withdrawal::STATUS_INIT? "selected":"" }}>
                                待打款
                            </option>
                            <option
                                value="{{Withdrawal::STATUS_PROCESSING}}" {{ $isSuccess == Withdrawal::STATUS_PROCESSING? "selected":"" }}>
                                提现中
                            </option>
                            <option
                                value="{{Withdrawal::STATUS_SUCCESS}}" {{ $isSuccess == Withdrawal::STATUS_SUCCESS? "selected":"" }}>
                                提现成功
                            </option>
                            <option
                                value="{{Withdrawal::STATUS_FAIL}}" {{ $isSuccess == Withdrawal::STATUS_FAIL? "selected":"" }}>
                                提现失败
                            </option>
                        </select>
                    </div>
                    <div class="form-group form-inline">
                        <!-- <label for="delivery">商家: </label> -->
                        <select class="form-control select2" name="shop_id" id="shop_id">
                            @if ($shopId != '')
                                <option value="{{$shopId}}">{{$shopName}}</option>
                            @else
                                <option value="">选择门店</option>
                            @endif
                        </select>
                    </div>
                    <div class="form-group">
                        <input class="form-control" type="text" name="search" id="" value="{{ $search }}"
                               placeholder="用户名">
                    </div>
                    <div class="form-group">
                        <input class="form-control" type="text" name="order_id" id="" value="{{ $orderId }}"
                               placeholder="订单id">
                    </div>
                    <br>
                    <div class="form-group form-inline" style="margin-top:15px">
                        <input class="form-control" type="text" placeholder="起始时间" id="start" name="start"
                               value="{{ $start }}"/>
                        -
                        <input class="form-control" type="text" placeholder="截止时间" id="end" name="end"
                               value="{{ $end }}"/>
                    </div>

                    <div class="form-group" style="margin-top:15px">
                        <input class="form-control" type="text" name="tx_name" id="" value="{{ $txName }}"
                               placeholder="提现人">
                    </div>


                    <button class="btn btn-success btn-ms" type="submit" style="margin-top:15px">搜索</button>
                    @can('withdrawal-export')
                        <button class="btn btn-primary btn-ms" type="submit" name="export" value="1" style="margin-top:15px">导出</button>
                    @endcan
                </form>
            </div>

            <br/>
            <div class="row">
                <div class="col-md-2" style="font-weight: bold">订单数量: {{ $count  }}</div>
                <div class="col-md-2" style="font-weight: bold">订单金额: {{$money}}</div>

            </div>
            <hr/>
            <table class="table table-striped table-hover">
                <thead>
                <tr>
                    <th style="min-width:120px">提现时间</th>
                    <th style="min-width:120px">用户名</th>
                    <th style="min-width:80px">头像</th>
                    <th style="min-width:100px">提现金额</th>
                    <th style="min-width:100px">提现途径</th>
                    <th style="min-width:80px">姓名</th>
                    <th style="min-width:100px">银行</th>
                    <th style="min-width:100px">账号</th>
                    <th style="min-width:80px">状态</th>
                    <th style="min-width:150px">订单ID</th>
                    <th style="min-width:300px">操作</th>
                </tr>
                </thead>
                <tbody>
                @foreach($data as $item)
                    <tr>
                        <td>{{ $item->created_at }}</td>
                        <td>{{ $item->name }}</td>
                        <td>
                            <img src="{{ $item->avatar }}" width="30">
                        </td>
                        <td>{{ $item->money/100 }}</td>
                        <td>{{ $item->channel }}</td>
                        <td>{{ $item->tx_name }}</td>
                        <td>{{ $item->bank_name }}</td>
                        <td>{{ $item->no }}</td>
                        <td>{{ \App\Modules\Withdrawal\Models\Withdrawal::$statusShow[$item->status] }}</td>
                        <td style="word-wrap:break-word;word-break:break-all; max-width: 150px">
                            @foreach(empty($item->order_id)? []: $item->order_id as $one)
                                <a href="{{ route('admin.order.detail', ['id' => $one]) }}">{{ $one }}</a>,
                            @endforeach
                        </td>
                        <td>
                            @can('withdrawal-edit')
                                <a class="btn btn-primary btn-xs"
                                   href="{{ route('admin.withdrawal.certificate', ['id' => $item->id]) }}"><i
                                        class="fa fa-check-circle"></i> 上传打款凭证</a>
                                @if (!empty($item->certificate))
                                    <a class="btn btn-info btn-xs show-cert"
                                       data-image="{{ file_url($item->certificate) }}"><i class="fa fa-file-image"></i>
                                        查看打款凭证</a>
                                @endif
                            @endcan
                        </td>
                    </tr>
                @endforeach
                </tbody>
            </table>
            {{ $data->appends(['search' => $search, 'is_success' => $isSuccess, 'shop_id' => $shopId, 'order_id' => $orderId, 'start' => $start, 'end' => $end, 'tx_name' => $txName])->links() }}
        </div>
    </div>
    <div class="modal fade loading custom-hide" style="width: 100%;text-align: center" id="hideForm2" tabindex="-1"
         role="dialog" aria-labelledby="hideFormLibel" aria-hidden="true" data-backdrop="static" data-keyboard="false">
        <div class="content invoice" style="position: relative; width: 60%; margin: auto">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
            </div>
            <div class="row" id="image-content">
            </div>
        </div>
    </div>
@endsection
@push('scripts')
    <script>
        $(".select2#shop_id").select2({
            width:"250px",
            ajax: {
                dataType: 'json',
                delay: 250,
                url: function () {
                    return '{{ route('admin.search_shops') }}';
                },
                processResults: function (data) {
                    return {
                        results: $.map(data, function (row, key) {
                            return {
                                id: key,
                                text: row
                            };
                        })
                    };
                }
            }
        });

        $('#start').datetimepicker({format: "Y-m-d",timepicker:false});
        $('#end').datetimepicker({format: "Y-m-d",timepicker:false});
        // $('#start').attr('readonly', 'readonly');
        // $('#end').attr('readonly', 'readonly');
        $.datetimepicker.setLocale('zh');
        
        $('.show-cert').on('click', function () {
            var k = $(this).attr('data-image');
            node = "<div style= \"float:left;margin: 10px;\">\n" +
                "       <img src=\"" + k + "\" width='100%'>\n" +
                "   </div>";
            $('#image-content').html(node);
            $("#hideForm2").modal('show');
        });
    </script>
@endpush
